package com.enjoyor.soa.traffic.server.tpcms.dubbo.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tpcms.InfoStopRoadDto;
import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetZoneDto;
import com.enjoyor.soa.traffic.api.dto.tpcms.StopRoadDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboStopRoadService;
import com.enjoyor.soa.traffic.core.tpcms.domain.InfoStopRoad;
import com.enjoyor.soa.traffic.core.tpcms.service.IRltBayonetZoneService;
import com.enjoyor.soa.traffic.core.tpcms.service.IStopRoadService;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

/**
 * 禁行线路DUBBO操作类
 * 
 * @author zsy 2018年4月26日
 *
 */
@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboStopRoadService implements IDubboStopRoadService {

    @Autowired
    private IStopRoadService stopRoadService;

    @Autowired
    private IRltBayonetZoneService rltBayonetZoneService;

    @Override
    public ResultPojo getStopRoadPage(Page page) {
        return new ResultPojo(stopRoadService.getStopRoadPage(page));
    }

    @Override
    public ResultPojo getStopRoadList(String stopRoadId, String stopRoadName, List<String> applyZoneIdList,
            String roadTypeId, String isUse) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("stopRoadId", stopRoadId);
        map.put("stopRoadName", stopRoadName);
        map.put("applyZoneIdList", applyZoneIdList);
        map.put("roadTypeId", roadTypeId);
        map.put("isUse", isUse);
        List<StopRoadDto> stopRoadDtoList = new ArrayList<StopRoadDto>();
        List<InfoStopRoad> stopRoadList = stopRoadService.getStopRoadList(map);
        for (InfoStopRoad infoStopRoad : stopRoadList) {
            StopRoadDto stopRoadDto = ReflectHelper.beanToBean(infoStopRoad, StopRoadDto.class);
            List<RltBayonetZoneDto> rltBayonetList = rltBayonetZoneService
                    .getRltBayonetList(stopRoadDto.getStopRoadId());
            stopRoadDto.setRltBayonetZone(ReflectHelper.listToList(rltBayonetList, RltBayonetZoneDto.class));
            stopRoadDtoList.add(stopRoadDto);
        }
        return new ResultPojo(stopRoadDtoList);
    }

    @Override
    public ResultPojo insertStopRoad(InfoStopRoadDto infoStopRoad, String userName) {
        stopRoadService.insertStopRoad(ReflectHelper.beanToBean(infoStopRoad, InfoStopRoad.class), userName);
        return new ResultPojo();
    }

    @Override
    public ResultPojo editStopRoad(InfoStopRoadDto infoStopRoad, String userName) {
        stopRoadService.editStopRoad(ReflectHelper.beanToBean(infoStopRoad, InfoStopRoad.class), userName);
        return new ResultPojo();
    }

    @Override
    public ResultPojo deleteStopRoad(String stopRoadId, String userName) {
        stopRoadService.deleteStopRoad(stopRoadId, userName);
        return new ResultPojo();
    }

    /**
     * 绘制地图位置信息
     */
    @Override
    public ResultPojo drawingRoadShape(InfoStopRoadDto infoStopRoad, String userName) {
        stopRoadService.drawingRoadShape(ReflectHelper.beanToBean(infoStopRoad, InfoStopRoad.class), userName);
        return new ResultPojo();
    }

}
